import { reactive, ref } from "vue"
import type { IBannerItem, ICustomHttpResponse, ITabsList, IWeather } from '@/simba/types/index';
import type { siTabsInstance } from "@/simba/types/component.d";
import AmapApi from "@/sheep/api/third/amap";

export const useSwiperIndex=()=>{
	const bannerList = ref<IBannerItem[]>([])
	
	const onGetSwiperBannerData = () =>{
		//获取对应的Swiper数据成功之后，将数据赋值
		bannerList.value = [
			{  
				id:'01',
				imgUrl: 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/shuijiao.jpg',  
				title: '昨夜星辰昨夜风, 画楼西畔桂堂东Hahah',  
			},  
			{  
				id:'02',
				imgUrl: 'https://yjy-xiaotuxian-dev.oss-cn-beijing.aliyuncs.com/picture/2021-04-15/6d202d8e-bb47-4f92-9523-f32ab65754f4.jpg',  
				title: '身无彩凤双飞翼, 心有灵犀一点通', 
			},  
			{  
				id: '03',
				imgUrl: 'https://yjy-xiaotuxian-dev.oss-cn-beijing.aliyuncs.com/picture/2021-04-15/1ba86bcc-ae71-42a3-bc3e-37b662f7f07e.jpg',  
				title: '谁念西风独自凉, 萧萧黄叶闭疏窗, 沉思往事立残阳',  
			},  
		]; 
	}
	
	return {
		bannerList, onGetSwiperBannerData
	}
}

export const useChooseWeather = () => {
	const tabList = [
			{id: 0, name: '天气提醒'},
			{id: 1, name: '土壤监测'}
		]
	const weatherTabs = reactive<ITabsList>({
		list: tabList,
		choosedTab: tabList[0],
		})
	
	return{
		weatherTabs
	}
}

export const useWeatherIndex =()=>{
	
	
	const currentDate = ref<IWeather>({})
	
	const onGetWeatherData= async()=>{
		const { code, data } = await AmapApi.getWeather('120115') as ICustomHttpResponse
		
		if(code !== 0){
			return;
		}
		//获取天气数据以及基于天气对植物的建议（是否需要针对不同植物类型的专属建议）
		const td = new Date()
		currentDate.value!.day = td.getFullYear() + '年' + (td.getMonth()+ 1) + '月' + td.getDate();
		
		switch(td.getDay()){
			case 0:
				currentDate.value!.week = '周日';
				break;
			case 1:
				currentDate.value!.week = '周一';
				break;
			case 2:
				currentDate.value!.week = "周二";
				break;  
			case 3:
				currentDate.value!.week = "周三";
				break;
			case 4:
				currentDate.value!.week = "周四";
				break;
			case 5:
				currentDate.value!.week = "周五";
				break;
			case 6:
				currentDate.value!.week = "周六";
				break;
		}
		
		
		currentDate.value!.weather = data.weather
		currentDate.value!.weatherIcon = 'https://flowers.oss-cn-beijing.aliyuncs.com/images/icon-weather/xiaoxue.png' //'/static/images/weather/天气_小雨.svg'
		currentDate.value!.temperature = data.temperature + '℃'
		currentDate.value!.suggest = '建议：暴晒可能对植物造成烫伤'
	}
	
	return {
		currentDate, onGetWeatherData
	}
}

export const usePantTabChoose = () => {
	const tabList = [
		{ id: 0, name: '浇水' },
		{ id: 1, name: '施肥' }
	]
	let plantTabs = reactive<ITabsList>({
		list: tabList,
		choosedTab: tabList[0],//默认为选择，与list中的
		// opName: '添加植物'
	})
	// console.log(listTabs, chooseItem.value, profile.profile?.levelName)
	const plantTabRef = ref<siTabsInstance>();//
	function onAddPlantHandler(){
		uni.showToast({
			icon:"none",
			title:'Hello onAddPlantHandler'
		})
	}
	
	return {
		plantTabs, plantTabRef, onAddPlantHandler
	}
}

